# This sample code uses the Appium python client
# pip install Appium-Python-Client
# Then you can paste this into a file and simply run with Python

from appium import webdriver
import pytest

class Test_Demo():
    def setup(self):
        devices = "192.168.123.170"
        # devices = "192.168.11.166:6666"
        caps = {}
        caps["platformName"] = "Android"
        caps["deviceName"] = devices
        caps["appPackage"] = "com.xueqiu.android"
        caps["appActivity"] = "view.WelcomeActivityAlias"
        caps["automationName"] = "uiautomator2"
        caps["skipServerInstallation"] = True
        caps["skipDeviceInitialization"] = True
        caps["autoGrantPermissions"] = True

        self.driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
        self.driver.implicitly_wait(10)
    def test_case001(self):
        # el1 = self.driver.find_element_by_id("com.xueqiu.android:id/ib_close")
        # el1.click()
        el2 = self.driver.find_element_by_id("com.xueqiu.android:id/tv_search")
        el2.click()
        el3 = self.driver.find_element_by_id("com.xueqiu.android:id/search_input_text")
        el3.send_keys("小米")
        el4 = self.driver.find_element_by_xpath(
            "/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.widget.LinearLayout/androidx.recyclerview.widget.RecyclerView/android.widget.RelativeLayout[1]/android.widget.LinearLayout/android.widget.TextView[1]")
        el4.click()
        el5 = self.driver.find_element_by_id("com.xueqiu.android:id/current_price")
        el5.click()


    def tearDown(self):
        self.driver.quit()





